package psn.hui.sys.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;
/**
 * 随机工具类
 * @author hui
 *
 */
public class RandomUtil {
	
	private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
	private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
	private static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
	private static Random random = new Random();
	/*
	 * 得到当前日期
	 */
	public static String getCurrentDateForString() {
		return sdf1.format(new Date());
	}
	/**
	 * 生成文件名-使用时间+4位随机数
	 * @param fileName
	 * @return
	 */
	public static String createFileNameUserTime(String fileName) {
		String fileSuffix = fileName.substring(fileName.lastIndexOf("."),fileName.length());
		String time = sdf2.format(new Date());
		Integer num = random.nextInt(9000)+1000;
		return time+num+fileSuffix;
	}
	/**
	 * 生成文件名-使用时间+4位随机数
	 * @param fileName
	 * @param suffix	临时文件后缀
	 * @return
	 */
	public static String createFileNameUserTime(String fileName,String suffix) {
		String fileSuffix = fileName.substring(fileName.lastIndexOf("."),fileName.length());
		String time = sdf2.format(new Date());
		Integer num = random.nextInt(9000)+1000;
		return time+num+fileSuffix+suffix;
	}
	
	
	
	/**
	 * 生成文件名-使用UUID
	 * @param fileName
	 * @return
	 */
	public static String createFileNameUseUUID(String fileName) {
		String fileSuffix = fileName.substring(fileName.lastIndexOf("."),fileName.length());
		return UUID.randomUUID().toString().replace("-", "").toUpperCase()+fileSuffix;
	}
	/**
	 * 	根据时间+5位随机数生成字符串
	 * @param rentidSuffix
	 * @return
	 */
	public static String createRandomStringUseTime(String rentidSuffix) {
		return rentidSuffix+"_"+sdf3.format(new Date())+"_"+(random.nextInt(90000)+10000);
	}

}
